<template>
  <!-- 易宝分账 -->
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label=" " prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label=" " prop="name">
        <el-select
          v-model="queryParams.orderState"
          @change="handleQuery"
          placeholder="分账状态"
          clearable
        >
          <el-option
            v-for="item in paymentStatusOptions"
            :key="item.id"
            :label="item.label"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="commodityList">
      <el-table-column label="序号" align="center" prop="id" width="55">
        <template slot-scope="scope">
          <div>
            {{
              scope.$index +
              (queryParams.pageNum - 1) * queryParams.pageSize +
              1
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="订单号"
        align="center"
        prop="money"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="订单总额"
        align="center"
        prop="bankurl"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="订单类型"
        :show-overflow-tooltip="true"
        align="center"
        prop="bank"
      />
      <el-table-column label="订单状态" align="center" prop="man">
      </el-table-column>
      <el-table-column
        :label="'下单日期 \n 付款日期'"
        align="center"
        prop="time"
      >
        <template slot-scope="scope">
          <div>
            {{ "2021-08-20" }}
          </div>
          <div>
            {{ "2021-08-20" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="分账方" align="center" prop="time" />
      <el-table-column label="分账状态" align="center" prop="time" />
      <el-table-column label="分账日期" align="center" prop="time" />
      <el-table-column label="平台" align="center" prop="time" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="100"
        v-if="queryParams.status != '0'"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handDetails(scope.row)"
            >明细</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 明细 -->
    <el-dialog
      title="订单分账明细"
      :visible.sync="open"
      width="50%"
      append-to-body
    >
      <el-form :model="details">
        <div class="form-title">
          <el-form-item label="订单号" prop="name">{{ details }} </el-form-item>
          <el-form-item label="订单总额" prop="name"
            >{{ details }}
          </el-form-item>
          <el-form-item label="供应商类型" prop="name"
            >{{ details }}
          </el-form-item>
          <el-form-item label="订单类型" prop="name"
            >{{ details }}
          </el-form-item>
          <el-form-item label="分账状态" prop="name">
            {{ details }}
          </el-form-item>
          <el-form-item label="分账时间" prop="name">
            {{ details }}
          </el-form-item>
        </div>
        <div>
          <h4>明细如下:</h4>

          <el-table :data="tableData" style="width: 100%">
            <el-table-column label="序号" align="center" prop="id" width="55">
              <template slot-scope="scope">
                <div>
                  {{
                    scope.$index +
                    (queryParams.pageNum - 1) * queryParams.pageSize +
                    1
                  }}
                </div>
              </template>
            </el-table-column>
            <el-table-column
              prop="date"
              label="易宝商户号"
              width="180"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
            <el-table-column prop="name" label="结算金额" width="180">
            </el-table-column>
            <el-table-column
              prop="address"
              label="备注"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
          </el-table>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listfinance } from "@/api/finance";
import Editor from "@/components/Editor";

export default {
  name: "commodity",
  components: {
    Editor,
  },
  data() {
    return {
      details: {}, //弹出框信息
      tableData: [
        {
          name: "10",
          date: "6222021901023456889",
          address: "工商银行长沙麓谷支行",
        },
        {
          name: "10",
          date: "6222021901023456889",
          address: "工商银行长沙麓谷支行",
        },
        {
          name: "10",
          date: "6222021901023456889",
          address: "工商银行长沙麓谷支行",
        },
      ], //弹出框表格
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公告表格数据
      commodityList: [
        {
          money: "10",
          bankurl: "6222021901023456889",
          bank: "工商银行长沙麓谷支行",
          man: "蒋文卓",
          time: "2021-08-20",
        },
        {
          money: "3",
          bankurl: "6222021901023456889",
          bank: "工商银行长沙麓谷支行",
          man: "蒋文卓",
          time: "2021-08-21",
        },
        {
          money: "2",
          bankurl: "6222021901023456889",
          bank: "工商银行长沙麓谷支行",
          man: "蒋文卓",
          time: "2021-08-21",
        },
        {
          money: "1",
          bankurl: "6222021901023456889",
          bank: "工商银行长沙麓谷支行",
          man: "蒋文卓",
          time: "2021-08-21",
        },
        {
          money: "10",
          bankurl: "6222021901023456889",
          bank: "工商银行长沙麓谷支行",
          man: "蒋文卓",
          time: "2021-08-20",
        },
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 类型数据字典
      statusOptions: [],
      // 状态数据字典
      typeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        closeState: "",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "商品名称不能为空", trigger: "blur" },
        ],
        noticeType: [
          { required: true, message: "公告类型不能为空", trigger: "change" },
        ],
      },
      type: "0",
      commodityBrandoptions: [],
    };
  },
  created() {
    // this.getList();
    this.getDicts("sys_notice_status").then((response) => {
      this.statusOptions = response.data;
    });
    this.getDicts("sys_notice_type").then((response) => {
      this.typeOptions = response.data;
    });
    this.getDicts("pp").then((response) => {
      this.commodityBrandoptions = response.data;
    });
  },
  methods: {
    handDetails() {
      this.open = true;
    },
    //   去提现
    getWithdraw() {
      this.open = true;
    },
    // 提现记录
    withdrawalRecord() {
      this.reset();
      this.$router.push({
        path: "/commodity/edit",
        query: {
          type: "reject",
          title: "驳回海关商品备案",
          data: row,
        },
      });
    },
    /** 查询公告列表 */
    handelcopy() {
      copycommodity().then((res) => {
        this.msgSuccess("复制成功");
      });
    },
    /** 查询公告列表 */
    changeStatus(value) {
      this.queryParams.pageNum = 1;
      //   this.getList();
    },
    getcheck() {
      this.$confirm;
    },
    /** 查询公告列表 */
    getList() {
      this.loading = true;
      listfinance(this.queryParams).then((response) => {
        var commodityList = response.rows;
        commodityList.map((item) => {
          var inventoryTotal = 0;
          if (item.specificationList) {
            item.specificationList.map((item) => {
              item.inventoryTotal = item.inventoryTotal
                ? item.inventoryTotal
                : 0;
              item.inventoryUsable = item.inventoryUsable
                ? item.inventoryUsable
                : 0;

              inventoryTotal += item.inventoryTotal;
            });
          }
          item.inventoryTotal = inventoryTotal;
        });
        this.commodityList = commodityList;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 公告状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 公告状态字典翻译
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.noticeType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        noticeTitle: undefined,
        noticeType: undefined,
        noticeContent: undefined,
        status: "0",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.$router.push({
        path: "/commodity/edit",
        query: {
          type: "add",
          title: "新增海关商品备案",
        },
      });
    },
    /** 审核按钮操作 */
    handleApproval(row) {
      const ids = row.id || this.ids;
      var obj = {
        id: ids,
        status: 0,
      };
      this.$confirm("是否确认审核该商品?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return approvalcommodity(obj);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("提交审核成功");
        })
        .catch(() => {});
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.$router.push({
        path: "/commodity/edit",
        query: {
          type: "edit",
          title: "修改海关商品备案",
          data: row,
        },
      });
    },
    handleUpdatereject(row) {
      this.reset();
      this.$router.push({
        path: "/commodity/edit",
        query: {
          type: "reject",
          title: "驳回海关商品备案",
          data: row,
        },
      });
    },
    handlemore(row) {
      this.reset();
      this.$router.push({
        path: "/commodity/edit",
        query: {
          type: "detail",
          title: "海关商品备案详情",
          data: row,
        },
      });
    },
    handlecopy(row) {
      this.$confirm("是否确认复制该商品?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return approvalcommodity(obj);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("复制成功");
        })
        .catch(() => {});
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            updatecommodity(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addcommodity(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm("是否确认删除该商品?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delcommodity(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    getbrand(row) {
      let commodityBrandoptions = this.commodityBrandoptions;
      let Brand = "";
      commodityBrandoptions.map((item) => {
        if (row.commodityBrand == item.dictValue) {
          Brand = item.dictLabel;
        }
      });
      return Brand;
    },
    getorderState(val) {
      let str = "";
      if (val == "1") {
        str = "待付款";
      } else if (val == "2") {
        str = "代发货";
      } else if (val == "3") {
        str = "待收货";
      } else if (val == "4") {
        str = "退换货";
      } else if (val == "5") {
        str = "已完成";
      } else if (val == "6") {
        str = "退换成功";
      } else if (val == "7") {
        str = "已关闭";
      }
      return str;
    },
  },
};
</script>
<style scoped lang="scss">
.radio-box {
  margin-bottom: 10px;
}
.stock {
  text-decoration: underline;
}
.copy {
  color: #999;
  cursor: pointer;
}
.box {
  display: flex;
  div {
    margin-right: 20px;
  }
}
</style>
<style lang="scss">
.el-table .cell {
  white-space: pre-line;
}

</style>